const connection = require("../config/db");

module.exports = class userService {
  static register(phone, password) {
    console.log(phone, password);
    const SQL = `insert into user(phone,password) values(?,?)`;
    return new Promise((resolve, reject) => {
      connection.query(SQL, [phone, password], function (err, data) {
        if (err) reject(err.message);
        resolve(data);
      });
    });
  }
  static login(phone, password) {
    const SQL = `select * from user where phone = ${phone} and password = ${password}`;
    return new Promise((resolve, reject) => {
      connection.query(SQL, function (err, data) {
        if (err) reject(err.message);
        else if (data.length == 0) reject("用户未找到，请去注册");
        else resolve(data);
      });
    });
  }
};
